include ../includes/head
block content
    include ../includes/header
.container-fluid
    .row
        include ../includes/slide
        .col-sm-9.col-sm-offset-3.col-md-10.col-md-offset-2.main
            h1.page-header 添加项目
            .row.placeholders
                //form.form-horizontal(role='form' action='/project/add' method='post')
                form.form-horizontal(role='form')
                    div.form-group
                        label.col-sm-5.control-label(for='name') 项目名称
                        div.col-sm-3
                            input.form-control(id='name' name='name' type='text' placeholder='项目名称' required)
                    div.form-group
                        label.col-sm-5.control-label(for='owner_company') 所属公司
                        div.col-sm-3
                            input.form-control(id='owner_company' name='owner_company' type='text' placeholder='所属公司' required)
                    div.form-group
                        label.col-sm-5.control-label(for='manage_company') 维护公司
                        div.col-sm-3
                            input.form-control(id='manage_company' name='manage_company' type='text' placeholder='维护公司' required)
                    div.form-group
                        label.col-sm-5.control-label(for='manage_id') 项目管理员
                        div.col-sm-3
                            select.form-control(id='manage_id' name='manage_id' type='text' placeholder='项目管理员')
                                if (result)
                                    each item in result
                                        if(item)
                                            option(value='#{item.id}') #{item.username}
                    div.form-group
                        label.col-sm-5.control-label(for='comment') 项目详情
                        div.col-sm-3
                            input.form-control(id='comment' name='comment' type='text' placeholder='项目详情' required)
                    div.form-group
                        label.col-sm-5.control-label
                        div.col-sm-1
                            //button.sub_btn.sub_left_btn#submitBtn(type='submit') 提交
                            button.sub_btn.sub_left_btn#submitBtn(type='button') 提交
                        div.col-sm-1
                            a(href='/project/list')
                                button.sub_btn.sun_right_btn(type='button') 取消

include ../includes/footer
    //AJAX调用添加接口
script(type='text/javascript').
    $("#submitBtn").click(function () {
        var project = new Object();
        if($("#name").val() == ""){
           return Tip.warning("请填写项目名称")
        }
        if ($("#owner_company").val() == "") {
            return Tip.warning("请填写所属公司名称")
        }
        if ($("#manage_company").val() == "") {
            return Tip.warning("请填写维护公司名称")
        }
        if ($("#manage_id").val() == "") {
            return Tip.warning("请选择一个管理员")
        }
        if ($("#comment").val() == "") {
            return Tip.warning("请填写项目详情")
        }
        project.name = $("#name").val();
        project.create_name = getString("userName");
        project.owner_company = $("#owner_company").val();
        project.manage_company = $("#manage_company").val();
        project.manage_id = $("#manage_id").val();
        project.comment = $("#comment").val();
        project.create_time = getTime();
        $.ajax({
            method: "POST",
            url: '/project/add',
            data: project,
            dataType: "json",
            success: function (data) {
                if (data.success == true) {
                    Tip.alert("add", "project","success");
                } else {
                    Tip.alert("add", "project","error");
                }
            },
            error: function (data) {
                Tip.alert("add", "project","error");
            }
        });

    });